<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="commons/head::myhead(~{::title},~{::link})">
    <title>sitelist</title>
    <!-- main CSS -->
    <link href="asserts/css/main.css" th:href="@{/asserts/css/main.css}" rel="stylesheet">
</head>
<body>
    <!--引入topbar-->
    <div th:replace="commons/bar::topbar"></div>
    <div class="container-fluid">
        <div class="row">
            <!--引入sidebar-->
            <div th:replace="commons/bar::#sidebar(activeUri='sitelist')"></div>
            <main role="main" class="col-md-10 ml-sm-auto col-lg-10 pt-3 px-4">
                <h2><a class="btn btn-sm btn-success" href="site/add.html" th:href="@{/main/site}">[[#{btn.add.site}]]</a></h2>
                <nav>
                    <div class="nav nav-tabs" id="nav-tab" role="tablist">
                        <a class="nav-item nav-link active" id="nav-hospital-tab" data-toggle="tab" href="#nav-hospital" role="tab" aria-controls="nav-hospital" aria-selected="true" th:text="#{place.hospital}">Hospital</a>
                        <a class="nav-item nav-link" id="nav-post-tab" data-toggle="tab" href="#nav-post" role="tab" aria-controls="nav-post" aria-selected="false" th:text="#{place.post}">Post</a>
                        <a class="nav-item nav-link" id="nav-population-tab" data-toggle="tab" href="#nav-population" role="tab" aria-controls="nav-population" aria-selected="false" th:text="#{place.population.point}">PopulationPoint</a>
                        <a class="nav-item nav-link" id="nav-other-tab" data-toggle="tab" href="#nav-other" role="tab" aria-controls="nav-other" aria-selected="false" th:text="#{common.other}">Other</a>
                    </div>
                </nav>
                <div class="tab-content" id="nav-tabContent">
                    <div class="tab-pane fade show active" id="nav-hospital" role="tabpanel" aria-labelledby="nav-hospital-tab">
                        <div class="table-responsive">
                            <table class="table table-striped table-sm">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>[[#{site.name}]]</th>
                                        <th>[[#{site.longitude}]]</th>
                                        <th>[[#{site.latitude}]]</th>
                                        <th>[[#{site.isfuel}]]</th>
                                        <th>[[#{common.operation}]]</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr th:each="site:${hospitals}">
                                        <td th:text="${site.id}"></td>
                                        <td th:text="${site.name}"></td>
                                        <td th:text="${site.coor.longitude}"></td>
                                        <td th:text="${site.coor.latitude}"></td>
                                        <td ><i th:if="${site.isSource}" class="fa fa-check"></i><i th:if="not ${site.isSource}" class="fa fa-times"></i></td>
                                        <td>
                                            <a class="btn btn-sm btn-primary" href="site/add.html" th:href="@{/main/site/}+${site.id}" th:text="#{btn.edit}">Edit</a>
                                            <button class="btn btn-sm btn-danger deleteBtn" th:attr="del_uri=@{/main/site/}+${site.id}" th:text="#{btn.delete}">Delete</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="nav-post" role="tabpanel" aria-labelledby="nav-post-tab">
                        <div class="table-responsive">
                            <table class="table table-striped table-sm">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>[[#{site.name}]]</th>
                                        <th>[[#{site.longitude}]]</th>
                                        <th>[[#{site.latitude}]]</th>
                                        <th>[[#{site.isfuel}]]</th>
                                        <th>[[#{common.operation}]]</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr th:each="site:${posts}">
                                        <td th:text="${site.id}"></td>
                                        <td th:text="${site.name}"></td>
                                        <td th:text="${site.coor.longitude}"></td>
                                        <td th:text="${site.coor.latitude}"></td>
                                        <td ><i th:if="${site.isSource}" class="fa fa-check"></i><i th:if="not ${site.isSource}" class="fa fa-times"></i></td>
                                        <td>
                                            <a class="btn btn-sm btn-primary" href="site/add.html" th:href="@{/main/site/}+${site.id}" th:text="#{btn.edit}">Edit</a>
                                            <button class="btn btn-sm btn-danger deleteBtn" th:attr="del_uri=@{/main/site/}+${site.id}" th:text="#{btn.delete}">Delete</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="nav-population" role="tabpanel" aria-labelledby="nav-population-tab">
                        <div class="table-responsive">
                            <table class="table table-striped table-sm">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>[[#{site.name}]]</th>
                                        <th>[[#{site.longitude}]]</th>
                                        <th>[[#{site.latitude}]]</th>
                                        <th>[[#{site.isfuel}]]</th>
                                        <th>[[#{common.operation}]]</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr th:each="site:${ppoints}">
                                        <td th:text="${site.id}"></td>
                                        <td th:text="${site.name}"></td>
                                        <td th:text="${site.coor.longitude}"></td>
                                        <td th:text="${site.coor.latitude}"></td>
                                        <td ><i th:if="${site.isSource}" class="fa fa-check"></i><i th:if="not ${site.isSource}" class="fa fa-times"></i></td>
                                        <td>
                                            <a class="btn btn-sm btn-primary" href="site/add.html" th:href="@{/main/site/}+${site.id}" th:text="#{btn.edit}">Edit</a>
                                            <button class="btn btn-sm btn-danger deleteBtn" th:attr="del_uri=@{/main/site/}+${site.id}" th:text="#{btn.delete}">Delete</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="nav-other" role="tabpanel" aria-labelledby="nav-other-tab">
                        <div class="table-responsive">
                            <table class="table table-striped table-sm">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>[[#{site.name}]]</th>
                                        <th>[[#{site.longitude}]]</th>
                                        <th>[[#{site.latitude}]]</th>
                                        <th>[[#{site.isfuel}]]</th>
                                        <th>[[#{common.operation}]]</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr th:each="site:${others}">
                                        <td th:text="${site.id}"></td>
                                        <td th:text="${site.name}"></td>
                                        <td th:text="${site.coor.longitude}"></td>
                                        <td th:text="${site.coor.latitude}"></td>
                                        <td ><i th:if="${site.isSource}" class="fa fa-check"></i><i th:if="not ${site.isSource}" class="fa fa-times"></i></td>
                                        <td>
                                            <a class="btn btn-sm btn-primary" href="site/add.html" th:href="@{/main/site/}+${site.id}" th:text="#{btn.edit}">Edit</a>
                                            <button class="btn btn-sm btn-danger deleteBtn" th:attr="del_uri=@{/main/site/}+${site.id}" th:text="#{btn.delete}">Delete</button>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </main>
            <form id="deleteSiteForm" method="POST">
                <!-- <input type="hidden" th:name="${_csrf.headerName}" th:value="${_csrf.token}"> -->
                <input type="hidden" name="_method" value="DELETE"/>
            </form>
        </div>
    </div>

    <div th:replace="commons/head::myscript(~{::script})">
        <script type="text/javascript">
            $(".deleteBtn").click(function(){
                // 删除制定id的坐标
                $("#deleteSiteForm").attr("action",$(this).attr("del_uri")).submit();
                return false;
            });
        </script>
    </div>
</body>
</html>